using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace AdventureWorks.Cinema.Client.Windows
{
    
    internal sealed partial class ChangePasswordForm : Form
    {
        public ChangePasswordForm()
        {
            InitializeComponent();

            errorProvider.SetIconAlignment(newPasswordTextBox,
                ErrorIconAlignment.TopLeft);
            errorProvider.SetIconPadding(newPasswordTextBox, 5);
            Application.Idle += new EventHandler(Application_Idle);
        }

        void Application_Idle(object sender, EventArgs e)
        {
            okButton.Enabled = (!String.IsNullOrEmpty(oldPasswordTextBox.Text) &&
                !String.IsNullOrEmpty(newPasswordTextBox.Text) &&
                !String.IsNullOrEmpty(confirmedNewPassword.Text));
        }

        public string OldPassword
        {
            get { return oldPasswordTextBox.Text; }
        }

        public string NewPassword
        {
            get { return newPasswordTextBox.Text; }
        }

        private void ChangePasswordForm_FormClosing(object sender,
            FormClosingEventArgs e)
        {
            Application.Idle -= new EventHandler(Application_Idle);
            if (DialogResult == DialogResult.OK)
            {
                if (newPasswordTextBox.Text != confirmedNewPassword.Text)
                {
                    errorProvider.SetError(newPasswordTextBox,
                        Resource.PasswordsDoNotMatch);

                    e.Cancel = true;
                }
            }
        }
    }
}